package com.weita.lightfood.controller;


import com.weita.lightfood.model.entity.HealthReport;
import com.weita.lightfood.service.HealthReportService;
import com.weita.lightfood.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author IT_Monster at 2019/04/19 21:52.
 * 健康报表
 */
@Api(tags = "健康报表管理接口")
@RestController
@RequestMapping("/healthReport")
public class HealthReportController {
    @Autowired
    private HealthReportService healthReportService;

    /**
     * 获取用户健康报表
     */
    @ApiOperation("获取用户健康报表")
    @ApiImplicitParam(name = "userId", value = "用户id", defaultValue = "0")
    @PostMapping("/getHealthReport")
    public Result<HealthReport> getHealthReport(int userId){
        try {
            return Result.success(healthReportService.getHealthReport(userId));
        } catch (Exception e) {
            return Result.fail("获取健康报表失败");
        }
    }

    /**
     * 判断用户是否有健康报表
     * @param userId
     * @return
     */
    @ApiOperation("判断用户是否有健康报表")
    @ApiImplicitParam(name = "userId", value = "用户id", defaultValue = "0")
    @PostMapping("/hasReport")
    public Result<Boolean> hasReport(int userId){
        try {
            return Result.success(healthReportService.hasReport(userId));
        } catch (Exception e) {
            return Result.fail("系统出错");
        }
    }
}
